import java.util.List;
import java.util.Scanner;

public class BookMain {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        BookDaoImpl bookDao = new BookDaoImpl();
        String name,author;
        int id = 0;
        double price;
        while (true){
            System.out.println("请输入你想要的操作");
            System.out.println("1、添加书籍");
            System.out.println("2、更新书籍");
            System.out.println("3、查询书籍（ID）");
            System.out.println("4、查询所有书籍");
            System.out.println("5、删除书籍");
            System.out.println("6、退出");
            String c = sc.nextLine();
            switch (c){
                case "1":
                    System.out.println("输入书名");
                    name = sc.nextLine();
                    System.out.println("输入作者");
                    author = sc.nextLine();
                    System.out.println("输入价格");
                    price = sc.nextDouble();
                    sc.nextLine();
                    bookDao.addBook(new Book(id,name,author,price));
                    break;
                case "2":
                    System.out.println("请输入id");
                    id = sc.nextInt();
                    System.out.println("输入书名");
                    name = sc.nextLine();
                    System.out.println("输入作者");
                    author = sc.nextLine();
                    System.out.println("输入价格");
                    price = sc.nextDouble();
                    sc.nextLine();
                    bookDao.updateBook(new Book(id,name,author,price));
                    break;
                case "3":
                    System.out.println("请输入id");
                    id = sc.nextInt();
                    sc.nextLine();
                    Book book = bookDao.getBookById(id);
                    System.out.println(book);
                    break;
                case "4":
                    List<Book> booklist = bookDao.getBookAll();
                    System.out.println(booklist);
                    break;

                case "5":
                    System.out.println("请输入id");
                    id = sc.nextInt();
                    sc.nextLine();
                    bookDao.deleteBook(id);
                    break;
                case "6":
                    System.out.println("退出程序。");
                    sc.close();
                    return;
                default:
                    System.out.println("无效的输入，请重新输入！\n");
            }
        }

    }
}
